/**
 * 休眠程序
 * @author wangsong
 * @param showMillisecond 休眠毫秒数
 * @date 2022/1/11 17:08
 * @return
 */
function sheep(showMillisecond) {
    // 执行时间
    return new Promise(resolve => {
        setTimeout(function () {
            resolve('resolved');
        }, showMillisecond);
    })
}


/**
 * 是否 pc打开
 * 返回true表示为pc端打开，返回false表示为手机端打开
 * @author wangsong
 * @param null
 * @date 2022/1/11 17:18
 * @return
 */
function isPc() {
    var userAgentInfo = navigator.userAgent;
    var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");
    var flag = true;
    for (var v = 0; v < Agents.length; v++) {
        if (userAgentInfo.indexOf(Agents[v]) > 0) {
            flag = false;
            break;
        }
    }
    return flag;
}

/**
 * 获取url 参数
 * @author wangsong
 * @param name key
 * @date 2020/12/13 0013 0:59
 * @return
 * @version 1.0.1
 */
function getUrlParam(name) {
    let url = window.location.href
    let p = url.split('?')[1]
    let params = new URLSearchParams(p)
    return params.get(name);
}



/**
 * 使用计算属性返回 分页
 * @author wangsong
 * @mail  1720696548@qq.com
 * @date  2022/10/31 0031 16:11
 * @version 1.0.0
 */
function getPages(current, totalCurrent) {
    // let start = 16;  // 当前页
    // let end = 27;   // 最后一页
    if (totalCurrent < 5) {
        let pages = [];
        for (let i = 0; i < totalCurrent; i++) {
            pages[i] = i + 1
        }
        return pages;
    }
    // 省略号的添加是分页大于10的时候
    if (current <= 2) {  //当前页码小于等于5
        //[1,2,3,4,5,6,'...',最后一页]
        return [1, 2, 3, '...', totalCurrent]
    } else if (current > totalCurrent - 2) {      //当前页码大于等于最后一页-5
        //[1,'...',尾页-5,尾页-4,尾页-3,尾页-2,尾页-1,尾页]
        return [1, '...', totalCurrent - 2, totalCurrent - 1, totalCurrent]
    } else { //当前页码大于5并且当前页码小于最后一页页码-5
        //[1,'...',当前页-3,当前页-2,当前页-1,当前页,当前页+1,当前页+2,当前页+3,'...',尾页]
        return [1, '...', current - 1, current, current + 1, '...', totalCurrent]
    }
}

